package com.huyun.web.modules.enum1;
/**
 * @author huyunqiang
 * @Date 2019/8/19 20:09
 */
public enum Status {

    SUCCESS(1,"成功"),FAILED(2,"失败");

    private Integer value;
    private String desc;

    public void setDesc(String desc) {
        this.desc = desc;
    }

    public void setValue(Integer value) {
        this.value = value;
    }

    public Integer getValue() {
        return value;
    }

    public String getDesc() {
        return desc;
    }

    Status(Integer value, String desc) {
        this.value = value;
        this.desc = desc;
    }

    public static Status getTypeByCode(Integer code){
        Status status = Status.SUCCESS;
        for(Status type:Status.values()){
            if(type.value == code){
                return type;
            }
        }

        return status;
    }

    public static String getDescByCode(Integer code){
        return getTypeByCode(code).desc;
    }


    public static void main(String[] args) {
        System.out.println(Status.getDescByCode(2));
        System.out.println(Status.SUCCESS.getValue());
    }

}
